package com.yzg.design;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author misterWei
 * @create 2020年05月15号:23点57分
 * @mailbox forcontinue@163.com
 */
@Slf4j(topic = "c.waitNotifyOrderOut")
public class WaitNotifyOrderOut {
    static final Object ROOM = new Object();
    static boolean flag = false;
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            synchronized (ROOM){
                while (!flag){
                    try {
                        ROOM.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                log.debug("2");

            }

        },"t1").start();
        TimeUnit.SECONDS.sleep(3L);
        new Thread(()->{
            synchronized (ROOM){
                ROOM.notifyAll();
                flag = true;
                log.debug("1");
            }
        },"t2").start();

    }



}
